<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace Model\UserBundle\Setting;

use Model\UserBundle\Model\UserModel;
use Model\UserGroupsBundle\Model\UserGroupsModel;

class UserLoginLogSetting{

    public $entityCnName = "用户登录记录";//后台管理显示的模块名称
    public $table = "UserLoginLog";//数据库表名
    public $editKeys = array();//允许管理列表中直接编辑的字段
    public $perPage = 10;//管理列表 每页显示条数


    /*自动获取的配置项*/
    public $entity;
    public $bundleName;
    public $entityName;
    public $SettingPath;
    public $entityPath;
    public $modelPath;
    public $doctrine;

    public function __construct($doctrine)
    {
        $this->bundleName = str_replace("\\","",str_replace("Setting","",__NAMESPACE__));
        $this->entityName = str_replace("\\","",str_replace("Setting","",str_replace(__NAMESPACE__,"",__CLASS__)));
        $this->SettingPath = __CLASS__;
        $this->entityPath = str_replace($this->entityName."Entity",$this->entityName,str_replace("Setting","Entity",__CLASS__));
        $this->entity = new $this->entityPath();
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
        $this->doctrine = $doctrine;
    }

    public function listConfig()
    {
        $default = array();
        $default["UserLoginLog"]["select"] = array("id","userAccount","loginTime","loginIp","userAgent","passwordError","loginRequest");
        $default["UserLoginLog"]["search"] = array("userAccount","loginIp","userAgent");
        $default["UserLoginLog"]["condition"] = array("passwordError");
        $default["UserLoginLog"]["orderBy"] = array("id","loginTime");

        $join = array();

        $join["User"]["on"] = "User.account = UserLoginLog.userAccount";
        $join["User"]["select"] = array("phone","nickName","addTime");
        $join["User"]["search"] = array();
        $join["User"]["condition"] = array();
        $join["User"]["orderBy"] = array();

        $join["UserGroups"]["on"] = "User.groups = UserGroups.id";
        $join["UserGroups"]["select"] = array("name","parent");
        $join["UserGroups"]["search"] = array();
        $join["UserGroups"]["condition"] = array();
        $join["UserGroups"]["orderBy"] = array();
        return array(
            "default"   => $default,
            "joins"     => $join,
        );
    }

    public function formConfig()
    {
//        $model = new UserGroupsModel($this->doctrine);
//        $categories = $model->getAllUserGroupsTree();
//        $parents[0] = "请选择分组";
//        foreach ($categories as $c) {
//            $parents[$c["id"]] = $c["name"];
//        }
//        $options["groups"]["other"] = array(
//            "choices"   => $parents,
//        );
//        $config["groups"] = array(
//            "label"     =>"用户组",
//            "showType"  =>"select",
//            "dataType"  =>"",
//            "option"    => $options["groups"]
//        );
//
//        $config["account"] = array(
//            "label"     =>"账号",
//            "showType"  =>"text",
//            "dataType"  =>"",
//            "option"    => array()
//        );
//
//        $config["password"] = array(
//            "label"     =>"密码",
//            "showType"  =>"text",
//            "dataType"  =>"",
//            "option"    => array()
//        );
//
//        $config["passwordPay"] = array(
//            "label"     =>"安全密码",
//            "showType"  =>"text",
//            "dataType"  =>"",
//            "option"    => array()
//        );
        $config = array();
        return $config;
    }
}